import json

from pypinyin import Style, lazy_pinyin


def generate_pinyin_dict():
    pinyin_dict = {}
    # 这里使用了一些常用的汉字，你可以根据需要扩展这个列表
    chinese_characters = "你好世界我爱编程".split()
    for char in chinese_characters:
        pinyin = ''.join(lazy_pinyin(char, style=Style.NORMAL))
        if pinyin not in pinyin_dict:
            pinyin_dict[pinyin] = [char]
        else:
            pinyin_dict[pinyin].append(char)
    return pinyin_dict


if __name__ == '__main__':
    with open('pinyin_to_chinese.json', 'w', encoding='utf-8') as f:
        json.dump(generate_pinyin_dict(), f, ensure_ascii=False)
